/*
 * Copyright @ 2024 weili23
 * com.example.jedisdemo.demos.utils 16:36
 * All right reserved.
 */

package com.example.jedisdemo.demos.utils;

import ch.qos.logback.core.net.SyslogOutputStream;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

/**
 * @desc: jedis连接池
 * @author: weili23
 * @createTime: 2024/3/12 16:36
 * @version: v1.0
 */
public class JedisConnectConfig {
    private static final JedisPool jedispool;
    static {
        System.out.println("============初始化连接池配置=================");
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        //最大连接
        jedisPoolConfig.setMaxTotal(8);
        //最大空闲连接
        jedisPoolConfig.setMaxIdle(8);
        //最小空闲连接
        jedisPoolConfig.setMinIdle(0);
        //设置最长等待时间
        jedisPoolConfig.setMaxWait(Duration.ofSeconds(10));
        jedispool = new JedisPool(jedisPoolConfig,"11.70.1.20",6379,1000,"123321");
    }

    //获取jedis对象
    public static Jedis getJedis(){
        return jedispool.getResource();
    }
}
